package comunications;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.ExportException;
import java.util.logging.Level;
import java.util.logging.Logger;
import server.ServerComunicateInterface;
import scala40rules.*;

public class Client {

	private ServerComunicateInterface c;
	private Registry registry;
    private int port;
    Logger logger = Logger.getLogger(this.getClass().getSimpleName());

	public Client() throws Exception{
            this.port=60001;
	}


        protected int getPort(){
            return port;
        }


	public void registryStartup(){

		try{

			Registry registry;

			registry = LocateRegistry.createRegistry(port);

			ClientComunicateImpl c = new ClientComunicateImpl();

		    registry.rebind("ClientComunicateImpl", c);

//		    System.out.println("Client Running...\n\n");
            logger.log(Level.INFO, "Client running...\n\n");

		}
                catch(ExportException ee){
                    port++;
                    registryStartup();
                }


                catch (Exception e) {
			logger.log(Level.WARNING, "[Client] Exception in registryStartup");
			e.printStackTrace();
		}
	}


}
